package my.study.java.lang.Class.examples.example1;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Ex01 extends Thread{

	/**
	 * 获取类的继承树
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		print(new String[1]);
		print(new Thread());
		print(new ArrayList<String>());		
	}
	public static void print(Object obj) {

		List<Class<?>> cls = getSuperClasses(obj);
		for (Class<?> cl : cls) {
			System.out.println(cl.getName());
		}
	}
	public static List<Class<?>> getSuperClasses(Object obj) {
		List<Class<?>> cls = new ArrayList<Class<?>>();
		Class<?> cl = obj.getClass();
		cls.add(cl);
		while (cl.getSuperclass() != Object.class && cl.getSuperclass() != null) {
			cl = cl.getSuperclass();
			
			cls.add(cl);
		}
		cls.add(Object.class);
		return cls;
	}

}
